<?php

namespace app\xwam\model;

/**
 * ProductFavorite 模型类
 *
 * @version VER:1.0; DATE:2016-9-3; AUTHOR:SoChishun; EMAIL:14507247@qq.com; DESC:Added.
 */
class ProductFavoriteModel extends AppbaseModel {

    /**
     * 数据表名称
     * @var string
     */
    protected $table = 't_product_favorite';

    /**
     * 是否批量验证
     * @var boolean
     */
    

    function add_favorite($product_id, $user_name) {
        $data = array(
            'product_id' => $product_id,
            'user_name' => $user_name,
        );
        if ($this->where($data)->count() > 0) {
            return xsfn_message(false); // 已经存在就不用再保存了
        }
        $result = $this->isUpdate(false)->save($data);
        return xsfn_message($result);
    }

    function get_favorite_paging_list(&$page, $where) {
        $options = array(
            'table' => 't_product_favorite f left join t_product_goods g on f.product_id=g.id',
            'where' => $where,
            'field' => 'f.id, f.product_id, f.user_name, g.title, g.price, g.picture_url',
        );
        return $this->selectPaging($page, $options);
    }

}
